﻿@using JinJun.YShow.Model;
@{
    var product = ViewBag.product as List<Product_Spu>;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link href="~/css/shop.css" type="text/css" rel="stylesheet" />
    <link href="~/css/Sellerber.css" type="text/css" rel="stylesheet" />
    <link href="~/css/bkg_ui.css" type="text/css" rel="stylesheet" />
    <link href="~/font/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="~/static/common/layui/css/layui.css" />
    <link rel="stylesheet" href="~/static/admin/css/style.css" />
    <script src="~/js/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="~/js/Sellerber.js" type="text/javascript"></script>
    <script src="~/js/jquery.dataTables.min.js"></script>
    <script src="~/js/jquery.dataTables.bootstrap.js"></script>
    <script src="~/js/layer/layer.js" type="text/javascript"></script>
    <script src="~/js/laydate/laydate.js" type="text/javascript"></script>
    <script src="~/js/hsCheckData.js" type="text/javascript"></script>
    <script src="~/layui-v2.5.4/layui/layui.js" type="text/javascript"></script>
    <script src="~/static/admin/js/script.js"></script>
    <!--[if lt IE 9]>
    <script src="js/html5shiv.js" type="text/javascript"></script>
    <script src="js/respond.min.js"></script>
    <script src="js/css3-mediaqueries.js"  type="text/javascript"></script>
      <![endif]-->
    <title>添加分类</title>
</head>

<body>
    <div class="margin inside_pages clearfix">
        <div class="add_style clearfix relative">
            <ul>
                <li class="clearfix"><label class="label_name col-xs-1"><i>*</i>图片描述：&nbsp;&nbsp;</label><div class="Add_content col-xs-11"><input name="" id="Pic_Desc" type="text" class="col-xs-2" /></div></li>
                <li class="clearfix">
                    <label class="label_name col-xs-1"><i>*</i>商品选择：&nbsp;&nbsp;</label>
                    <div class="Add_content col-xs-11">
                        <select id="product">
                            @for (int i = 0; i < product.Count; i++)
                            {
                                <option value=@product[i].Id>@product[i].Name</option>
                            }
                        </select>
                    </div>
                </li>
                <li class="clearfix">
                    <div class="layui-upload">
                        <button class="layui-btn" id="test1" style="margin-left:2%" type="button">上传图片</button>
                        <div class="layui-upload-list" style="margin-left:2%">
                            <img class="layui-upload-img" id="demo1" style="width:200px;height:200px" />
                            <p id="demoText"></p>
                        </div>
                    </div>
                </li>
                <li class="clearfix"><label class="label_name col-xs-1"><i>*</i>图片排序：&nbsp;&nbsp;</label><div class="Add_content col-xs-11"><input name="" id="Pic_Order" type="text" class="col-xs-2" /></div></li>
                <li class="clearfix">
                    <label class="label_name col-xs-1"><i>*</i>图片地址：&nbsp;&nbsp;</label>
                    <div class="Add_content col-xs-11">
                        <div class="layui-input-inline">
                            <input type="text" id="PicUrl" name="title" placeholder="" autocomplete="off" class="layui-input" />
                        </div>
                    </div>
                </li>
            </ul>
                <form class="layui-form ">
                    <ul>
                        <li class="clearfix">
                            <label class="label_name col-xs-1"><i>*</i>是否主图：&nbsp;&nbsp;</label>
                            <div class="Add_content col-xs-11">
                                <div class="layui-input-block">
                                    <input type="checkbox" id="Is_Master" value="1" name="top" lay-text="是|否" lay-skin="switch" />
                                </div>
                            </div>
                        </li>
                        <li class="clearfix">
                            <label class="label_name col-xs-1"><i>*</i>是否有效：&nbsp;&nbsp;</label>
                            <div class="Add_content col-xs-11">
                                <div class="layui-input-block">
                                    <input type="checkbox" id="Pic_Status" value="1" name="state" lay-text="是|否" lay-skin="switch" />
                                </div>
                            </div>
                        </li>
                    </ul>
                </form>
        </div>
    </div>
        <div class="Button_operation btn_width">
            <input id="commit" class="btn button_btn bg-deep-blue" type="button" value="保存并添加" />
            <button class="btn button_btn bg-gray" id="exit" type="button">取消添加</button>
        </div>
</body>
</html>

<script>
    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: '/Picture/UploadImage'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                else {
                    //上传成功,获取图片路径
                    $("#PicUrl").val(res.FilePath);
                }
            }
            //    , error: function () {
            //        //演示失败状态，并实现重传
            //        var demoText = $('#demoText');
            //        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
            //        demoText.find('.demo-reload').on('click', function () {
            //            uploadInst.upload();
            //        });
            //    }
            //});
        });
    });

    $("#exit").click(function () {
        window.location.href="/Home/Picture"
    });

     //添加按钮点击事件
    $("#commit").click(function () {
        var data = {};
        data.ProductId = $("#product").val();
        data.Pic_Desc = $("#Pic_Desc").val();
        data.Pic_Url = $("#PicUrl").val();
        data.Is_Master = $("#Is_Master").val();
        data.Pic_Order = $("#Pic_Order").val();
        data.Pic_Status = $("#Pic_Status").val();
        $.ajax({
            url: "/Picture/AddPicture",
            type: "post",
            data:data,
            success: function (result) {
                if (result.Success) {
                    layer.msg('新增成功！',
                        {
                            icon: 1,
                            time: 2000,
                            shade: 0.2
                        }, function () {
                            window.location.href="/Home/Picture"
                        });
                }
                else
                {
                    layer.msg('新增失败！',
                    {
                            icon: 1,
                            time: 2000,
                            shade: 0.2
                    });
                }
            }
        })
    });

</script>
